package reduce.fz.com.reduce.util.share;

import android.app.Activity;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import reduce.fz.com.reduce.util.ToastUtil;

/**
 * Created by qingshengzheng on 16/1/10.
 */
public class ShareOper implements PlatformActionListener {
    private Activity mActivity;

    /**
     * qq登陆
     */
    public void qqLogin() {
        ShareSDK.closeDebug();
        ShareSDK.initSDK(mActivity);
        Platform qq = ShareSDK.getPlatform(QQ.NAME);
        qq.SSOSetting(false);  //设置false表示使用SSO授权方式
        qq.setPlatformActionListener(this); // 设置分享事件回调
        qq.authorize();
    }

    /**
     * 微博登陆
     */
    public void weiboLogin() {
        ShareSDK.closeDebug();
        ShareSDK.initSDK(mActivity);
        Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME);
        if (weibo == null) {
            ToastUtil.showMessage("微博登录异常");
            return;
        }
        weibo.SSOSetting(false);  //设置false表示使用SSO授权方式
        weibo.setPlatformActionListener(this); // 设置分享事件回调
        weibo.authorize();
    }

    /**
     * webcht登陆
     */
    public void webchatLogin() {
        ShareSDK.closeDebug();
        ShareSDK.initSDK(mActivity);
        Platform wechat = ShareSDK.getPlatform(Wechat.NAME);
        wechat.SSOSetting(false);  //设置false表示使用SSO授权方式
        wechat.setPlatformActionListener(this); // 设置分享事件回调
        wechat.authorize();
    }


    @Override
    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

    }

    @Override
    public void onError(Platform platform, int i, Throwable throwable) {

    }

    @Override
    public void onCancel(Platform platform, int i) {

    }
}
